import type { StateStorage } from "zustand/middleware"

export const storage: StateStorage = {
  getItem: async (name: string): Promise<string | null> => {
    const result = (await chrome.storage.local.get(name)) || null
    return result != undefined && result[name]
  },
  setItem: async (name: string, value: string): Promise<void> => {
    // console.log("name: ", name)
    // console.log("value: ", value)
    await chrome.storage.local.set({ [name]: value })
  },
  removeItem: async (name: string): Promise<void> => {
    await chrome.storage.local.remove(name)
  }
}
